import React, { useEffect, useState } from 'react';
import { Divider } from 'antd';
import ProForm, { ProFormText } from '@ant-design/pro-form';
import { getPlanOrderDetail } from '@/services/order/api';
import { showMsg } from '@/utils/utils';
import { PlanOrderStatus } from '@/utils/constants';

interface PatientInfoProps {
  order_id?: string;
  type?: string;
}

const PatientInfo: React.FC<PatientInfoProps> = (props) => {
  const { order_id } = props;
  const [detail, setDetail] = useState<any>({});

  useEffect(() => {
    if (order_id) {
      getPlanOrderDetail(order_id).then(data => {
        setDetail(data);
      }).catch(err => {
        showMsg(err?.data?.errmsg);
      });
    }
  }, [order_id]);
  
  return <div className="service-record">
     <div className="header">
        <div className="title">1.住院患者信息</div>
        <div className="btns">
          计划状态：<span style={{color: '#52C41A'}}>{detail.plan_status ? PlanOrderStatus[detail.plan_status] : '待创建'}</span>
        </div>
      </div>
      <Divider />
      <ProForm submitter={{
        searchConfig: {
          submitText: '查询'
        },
        submitButtonProps: {
          style: {
            display: detail.admission_num ? 'none' : 'block'
          }
        },
        resetButtonProps: {
          style: {
            display: 'none'
          }
        }
      }} layout='inline'>
        <ProForm.Group>
          <ProFormText
            label="住院号"
            width={150}
            fieldProps={{
              value: detail.admission_num
            }}
          />
          <ProFormText
            label="患者姓名"
            width={150}
            disabled={!!order_id}
            fieldProps={{
              value: detail.patient_name
            }}
          />
          <ProFormText
            label="归属科室"
            width={150}
            fieldProps={{
              value: detail.create_dept_name
            }}
          />
          <ProFormText
            label="床位号"
            width={150}
            fieldProps={{
              value: detail.bed_no
            }}
          />
        </ProForm.Group>
      </ProForm>
  </div>
}
export default PatientInfo;